﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Game1942.Library.View
{
    //Como falta la clase score la dejamos asi y despues le agregamos el observer
    public class ScoreView : IObserver<int>, IView
    {
        private SpriteFont font;
        private int score = 0;
        private int xPos, yPos;
        private IDisposable unsubscriber;

        //For the score is in top center of the screen, passed as parameters:
        //xPos = GraphicsDevice.Viewport.Width/2
        //yPos = 10
        public ScoreView(int xPos, int yPos)
        {
            this.xPos = xPos;
            this.yPos = yPos;
        }

        public void LoadContent(SpriteFont font)
        {
            this.font = font;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(font,
                "SCORE : " + score.ToString(),
                new Vector2(xPos - 50, yPos),
                Color.White);
        }

        public bool Visible()
        {
            throw new NotImplementedException();
        }

        #region [Observer Methods]

        public void Subscribe(IObservable<int> provider)
        {
            if (provider != null)
                unsubscriber = provider.Subscribe(this);
        }
        
        //Provides the observer with new data.
        public void OnNext(int value)
        {
            score = (value);
        }

        //Notifies the observer that the provider has experienced an error condition.
        public void OnError(Exception error)
        {
            //Do nothing
        }

        //Notifies the observer that the provider has finished sending push-based notifications.
        public void OnCompleted()
        {
            unsubscriber.Dispose();
        }

        #endregion
    }
}
